package amartin47;

import java.awt.Button;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.LayoutManager;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.*;

import javax.swing.*;

public class PageChooser extends JComponent
{
	List<ChoosableText> slides;
	Slide selectedSlide;
	
	public PageChooser() {
		super();

		LayoutManager layout;
		layout = new GridLayout(0,3,5,5);
		this.setLayout(layout);
		
		slides = new ArrayList<ChoosableText>();
		/*slides.add(new ChoosableText("Drew", "Working the farm\nHard every Saturday\nOh how I love you", this));
		slides.add(new ChoosableText("Luke", "Love\nStuff", this));
		slides.add(new ChoosableText("Jake", "Thanks for being a friend\ndun dun dun", this));
		slides.add(new ChoosableText("Josh", "Thanks for being a friend\ndun dun dun", this));
		slides.add(new ChoosableText("Run", "Thanks for being a friend\ndun dun dun", this));
		slides.add(new ChoosableText("Run", "Thanks for being a friend\ndun dun dun", this));
		slides.add(new ChoosableText("Run", "Thanks for being a friend\ndun dun dun\nhelp me out plz", this));
		slides.add(new ChoosableText("Run", "Thanks for being a friend\ndun dun dun", this));*/
		this.addSlidesToFrame();
		
		this.setMinimumSize(new Dimension(500,300));
		this.setPreferredSize(new Dimension(500, 300));
	}
	
	public void setSelectedSlide(Slide slide)
	{
		synchronized(this)
		{
			this.selectedSlide = slide;
		}
	}
	
	public Slide getSelectedSlide()
	{
		return this.selectedSlide;
	}
	
	public void setSlides(List<Slide> slides)
	{
		this.clearSlides();
		for (Slide slide : slides)
		{
			this.slides.add(new ChoosableText(slide, this));
		}
		this.addSlidesToFrame();
	}
	
	private void clearSlides()
	{
		for(ChoosableText t : slides)
		{
			this.remove(t);
		}
		slides.clear();
	}
	
	private void addSlidesToFrame()
	{
		for(ChoosableText t : slides)
		{
			this.add(t);
		}
		this.validate();
		this.repaint();
	}
	public void deselectAll()
	{
		for(ChoosableText t : slides)
		{
			t.deselect();
		}
	}
	
	/*protected void paintComponent(Graphics g)
	{
		//super.paintComponent(g);
		g.fillRect(0, 0, 50, 50);
		
	}*/
}
